package com.stations.controller;

import com.github.pagehelper.PageInfo;
import com.stations.common.constant.ControllerConstant;
import com.stations.common.web.base.BaseController;
import com.stations.common.web.domain.request.PageDomain;
import com.stations.common.web.domain.response.Result;
import com.stations.common.web.domain.response.module.ResultTable;
import com.stations.domain.RunningStatus;
import com.stations.domain.SRunStatus;
import com.stations.domain.SysNotice;
import com.stations.domain.TTransmitter;
import com.stations.domain.dtree.DTree;
import com.stations.domain.dtree.DTreeResponse;
import com.stations.domain.dtree.Status;
import com.stations.service.TrasmiterService;
import com.stations.websocket.WebSocketService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Describe: 发射机控制器
 * Author: Ljy
 * CreateTime: 2019/10/23
 */
@RestController
@Api(tags = {"发射机管理"})
@RequestMapping(ControllerConstant.API_SYSTEM_PREFIX + "transmitter")
public class TransmiterController extends BaseController {

    /**
     * Describe: 基础路径
     */
    private static String MODULE_PATH = "system/transmitter/";

    @Resource
    private TrasmiterService sysTrasmiterService;


    /**
     * Describe: 获取台站列表视图
     * Param ModelAndView
     * Return 发射机视图
     */
    @GetMapping(value = "/getStations")
    @ApiOperation(value = "获取台站列表")
    @PreAuthorize("hasPermission('/system/transmitter/getStations','sys:transmitter:getStations')")
    public DTreeResponse getStations(HttpServletRequest request) {
        List<DTree> RegionList = sysTrasmiterService.getTree();
        DTreeResponse response=new DTreeResponse();
        response.setData(RegionList);
        response.setStatus(new Status());
        return response;
    }

    /**
     * Describe: 根据台站ID获取发射机列表
     * Param ModelAndView
     * Return 发射机
     */
    @GetMapping(value = "/getTransmitter")
    @ApiOperation(value = "根据台站ID获取发射机列表")
    @PreAuthorize("hasPermission('/system/transmitter/getTransmitter','sys:transmitter:getTransmitter')")
    public Result getTransmiter(Integer stationCode) {
        List<TTransmitter> lisTTransmitter = sysTrasmiterService.selectTTransmitter(stationCode);
        return Result.success(lisTTransmitter);
    }


    /**
     * Describe: 根获取所有发射机列表
     * Param ModelAndView
     * Return 发射机视图
     */
    @GetMapping(value = "/getAllTransmitter")
    @ApiOperation(value = "获取所有发射机列表")
    @PreAuthorize("hasPermission('/system/transmitter/getAllTransmitter','sys:transmitter:getAllTransmitter')")
    public Result getAllTransmitter() {
        List<TTransmitter> lisTTransmitter = sysTrasmiterService.getAllTransmitter();
        return Result.success(lisTTransmitter);
    }

    /**
     * 分页查询发射机列表
     */
    @ResponseBody
    @GetMapping("/data")
    @PreAuthorize("hasPermission('/system/transmitter/data','sys:transmitter:data')")
    public ResultTable list(@ModelAttribute TTransmitter tTransmitter, PageDomain pageDomain) {
        PageInfo<TTransmitter> pageInfo = sysTrasmiterService.selectTTransmitterPage(tTransmitter, pageDomain);
        return pageTable(pageInfo.getList(), pageInfo.getTotal());
    }

    /**
     * Describe: 删除发射机
     * Param ModelAndView
     * Return 发射机视图
     */
    @PostMapping("delTransmitter")
    @ApiOperation(value = "获取发射机列表视图")
    @PreAuthorize("hasPermission('/system/transmitter/getTransmitterDetail','sys:transmitter:getTransmitterDetail')")
    public Result delTransmitter(@RequestBody TTransmitter tTransmitter) {
        return sysTrasmiterService.delTransmitter(tTransmitter);
    }

    /**
     * Describe: 发射机添加
     * Param ModelAndView
     * Return 发射机
     */
    @PostMapping("addTransmitter")
    @ApiOperation(value = "添加获取发射机列表")
    @PreAuthorize("hasPermission('/system/transmitter/addTransmitter','sys:transmitter:addTransmitter')")
    public Result addTransmitter(@RequestBody TTransmitter tTransmitter) {
        return sysTrasmiterService.addTransmitter(tTransmitter);
    }


    /**
     * Describe: 编辑发射机
     * Param ModelAndView
     * Return 发射机
     */
    @PostMapping("editTransmitter")
    @ApiOperation(value = "编辑获取发射机列表")
    @PreAuthorize("hasPermission('/system/transmitter/editTransmitter','sys:transmitter:editTransmitter')")
    public Result editTransmitter(@RequestBody TTransmitter tTransmitter) {
        return sysTrasmiterService.editTransmitter(tTransmitter);
    }

    /**
     * 获取发射机运行状态参数
     */
    @ResponseBody
    @PostMapping("/getTransmitterRunningStatus")
    @PreAuthorize("hasPermission('/system/transmitter/getTransmitterRunningStatus','sys:transmitter:getTransmitterRunningStatus')")
    public Result getTransmitterRunningStatus(@RequestBody RunningStatus runningStatus) {
        RunningStatus sRunStatus = sysTrasmiterService.getTransmitterRunningStatus(runningStatus);
        return Result.success(sRunStatus);
    }


}
